/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1602.czq.dao.impl;

import edu.fjut.se1602.czq.dao.PetStoreDao;
import edu.fjut.se1602.czq.entity.PetOwner;
import edu.fjut.se1602.czq.entity.PetStore;
import edu.fjut.se1602.czq.util.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author asus
 */
public class PetStoreDaoImpl implements PetStoreDao {

  

    @Override
    public int Login(String userName, String userPassword) {
        int r = 0;
        try {
            Connection con = DBUtil.getConnection();
            PreparedStatement pst = con.prepareStatement("select * from store where name=? and password=?");
            pst.setString(1, userName);
            pst.setString(2, userPassword);
            ResultSet rs = pst.executeQuery();
            if (rs.next()) {
                System.out.println("------恭喜你登陆成功！------");
            } else {
                System.out.println("登录失败！");
            }
        } catch (SQLException ex) {
            Logger.getLogger(PetOwnerDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return r;
    }

    @Override
    public List<PetStore> getAllStores() {
                List<PetStore> arraylist = new ArrayList<PetStore>();
        try {
            Connection con = DBUtil.getConnection();
            ResultSet rs = con.createStatement().executeQuery("select * from store");
            while (rs.next()) {
                PetStore petstore = new PetStore();
                petstore.setID(rs.getInt("ID"));
                petstore.setName(rs.getString("name"));
                petstore.setPassword(rs.getString("password"));
                petstore.setBalance(rs.getDouble("balance"));
                arraylist.add(petstore);
            }
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(PetDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return arraylist;
    }
}
